﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleCreditCardApp
{

    class Program
    {
        class CreditCardDelegete
        {
            public delegate void card(User uesr);
            public event card DeMoney;//定期扣款事件绑定委托

            //判断事件是否启用
            public void DeMoneyTest(User user)
            {
                if (DeMoney != null)
                {
                    DeMoney(user);
                }
                else
                {
                    Console.WriteLine("还款日未到");
                }
            }
        }
        class Bank
        {
            public void DeMoneying(User user)
            {
                Console.WriteLine("{0},您的信用卡余额为{1}元，本次还款{2}元，信用卡目前余额为{3}元！",
                     user.Name, user.Balance, user.Debt, (user.Balance - user.Debt));
                Console.WriteLine();
            }
        }

        class User
        {
            private int balance;
            private int debt;
            private string name;
            private int day;
            public User(int balance, int debt, string name, int date)
            {
                this.balance = balance;
                this.debt = debt;
                this.name = name;
                this.day = date;
            }
            //属性，用匿名函数赋值、取值
            public int Balance { get => balance; set => balance = value; }
            public string Name { get => name; set => name = value; }
            public int Debt { get => debt; set => debt = value; }
            public int Date { get => day; set => day = value; }
        }
        static void Main(string[] agrs)
        {
            CreditCardDelegete d1 = new CreditCardDelegete();

            User user = new User(5220, 520, "马化腾", 8000);
            Bank bank = new Bank();

            d1.DeMoney += bank.DeMoneying;//银行扣款函数订阅扣款事件


            for (int i = 0; i <= 10000; i++)
            {
                if (i == user.Date)
                    d1.DeMoneyTest(user);
            }
        }
    }

}